<?php

/**
 * seo actions.
 *
 * @package    sf_sandbox
 * @subpackage seo
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class seoActions extends autoseoActions
{
	public function handleErrorSave()
    {
    	//parent::handleErrorSave();
        $this->seo = $this->getSeoOrCreate();
        $this->updateSeoFromRequest();
        $this->labels = $this->getLabels();
        
        $this->setTemplate('edit');
        return sfView::SUCCESS;
    }
	protected function getLabels()
  	{
  		$labels = parent::getLabels();
  		$labels['seo[url]'] = 'Url:';
	    return $labels;
  	}
  	public function executeCreateNew()
  	{
  		/* @var $this->seo Seo */
  		$this->labels = $this->getLabels();
        $c = new Criteria();
    	$c->add(SeoPeer::OBJ_TYPE, $this->getRequestParameter('obj_type'));
    	$c->add(SeoPeer::OBJ_ID, $this->getRequestParameter('obj_id'));
    	$c->add(SeoPeer::OBJ_ACTION, $this->getRequestParameter('obj_action'));
    	$c->add(SeoPeer::CULTURE, get_culture());
    	$seoObj = SeoPeer::doSelectOne($c);
		if($seoObj)
		{
			$this->seo = $seoObj;
		}else
		{
	        $this->seo = new Seo();
	        $this->seo->setObjType($this->getRequestParameter('obj_type'));
	        $this->seo->setObjAction($this->getRequestParameter('obj_action'));
	        $this->seo->setObjId($this->getRequestParameter('obj_id'));
	        $this->seo->setCulture(get_culture());
	        $new = NewsPeer::retrieveByPK($this->getRequestParameter('obj_id'));
	        if($new)
	        {
	        	$this->seo->setUrl(Seo::slugify($new->getName()));
	        }
		}
  		
  		$this->setTemplate('edit');
  	}
  	
	protected function saveSeo($seo)
  	{
  		$this->setFlash('seoReturnUrl', $this->getFlash('seoReturnUrl'));
    	parent::saveSeo($seo);
  	}
}
